home *** CD-ROM | disk | FTP | other *** search
/ Invisible Universe / Invisible Universe (1995)(Voyager)[Mac-PC].iso / mac / UNIVERSE / SHARED.DIR / 01020_Script_underline and bold handlers < prev    next >
Text File  |  1995-11-21  |  5KB  |  200 lines

  1. on doTextClick cn
  2.   global gMouseDownTime, gPunctuation, gUnderlineCount
  3.   
  4.   --put ">>>doTextClick on " & cn
  5.   
  6.   if the ticks < (gMouseDownTime + 80) then exit
  7.   
  8.   --beep
  9.   
  10.   set mw = the mouseWord
  11.   set mc = the mouseChar
  12.   
  13.   if voidP(cn) then 
  14.     set cn = the mouseCast
  15.   end if
  16.   
  17.   if voidP(gPunctuation) then
  18.     set gUnderlineCount = length(field "Underline List")
  19.     set gPunctuation = ":,.;)( " & quote & return
  20.   end if
  21.   
  22.   
  23.   if (the castType of cast cn) <> #text then exit
  24.   
  25.   set ts = the textStyle of word mw of field cn
  26.   if ts = "plain" then exit
  27.   
  28.   
  29.   if ts = "bold" then
  30.     doBoldText mw, cn
  31.   else
  32.     doUnderlineText mc, cn
  33.   end if  
  34.   
  35. end doTextClick
  36.  
  37.  
  38.  
  39. on doBoldText mw, cn
  40.   global gPunctuation
  41.   
  42.   set thePhrase = word mw of field cn
  43.   
  44.   set i = mw - 1 
  45.   
  46.   repeat while i > 0
  47.     if (the textStyle of word i of field cn) <> "bold" then exit repeat
  48.     set thePhrase = word i of field cn && thePhrase
  49.     set i = i - 1
  50.   end repeat
  51.   
  52.   set i = mw + 1 
  53.   set last = the number of words of field cn
  54.   
  55.   repeat while i < last
  56.     if (the textStyle of word i of field cn) <> "bold" then exit repeat
  57.     set thePhrase = thePhrase && word i of field cn 
  58.     set i = i + 1
  59.   end repeat
  60.   
  61.   set l = the number of chars in thePhrase
  62.   
  63.   repeat while gPunctuation contains (char l of thePhrase)
  64.     set l = l - 1
  65.     if l = 0 then
  66.       alert "Note that word " & mw && "of cast" && cn && "is only punctuation."
  67.       return
  68.     end if
  69.     
  70.   end repeat
  71.   
  72.   set thePhrase = char 1 to l of thePhrase
  73.   
  74.   --put ">>>doTextClick: bold" && thePhrase
  75.   
  76.   set off = offset(thePhrase, field "BOLD List")
  77.   if off <> 0 then 
  78.     
  79.     --- tbd dmd remove line ???
  80.     
  81.     if char (off-1) of field "BOLD List" <> ">" then
  82.       alert ¼
  83. "Minor error in doTextClick for bold field... missing " & quote ">" & quote
  84.     end if
  85.     
  86.     set lineNum = integer(char (off-3) to (off-2) of field "BOLD List")
  87.     
  88.     --put ">>>line = " & line lineNum of field "Bold List"
  89.     
  90.     --
  91.     --
  92.     -- Note that item 4 contains a value if we need a unique match on 
  93.     -- both the term and the cast member
  94.     --
  95.     if empty <> item 4 of line lineNum of field "BOLD List" then
  96.       repeat while 1
  97.         --
  98.         --
  99.         -- Check for a matching cast member
  100.         --
  101.         if cn = integer(item 2 of line lineNum of field "BOLD List") then exit repeat
  102.         
  103.         --put ">>> going to next line"
  104.         
  105.         --
  106.         --
  107.         -- Try the next item in the list
  108.         --
  109.         
  110.         set lineNum = lineNum + 1
  111.         
  112.         set newPhrase = item 1 of line lineNum of field "BOLD List"
  113.         set l = the number of chars in newPhrase
  114.         set newPhrase = char 5 to l of newPhrase
  115.         
  116.         --
  117.         --
  118.         -- Check if the next term matches, if not, exit.
  119.         --
  120.         if newPhrase <> thePhrase then
  121.           set off = 0
  122.           exit repeat
  123.         end if
  124.         
  125.       end repeat
  126.       
  127.     end if
  128.     
  129.   end if
  130.   
  131.   --
  132.   --
  133.   -- Do the bold goto
  134.   --
  135.   
  136.   --put ">>> BOLD click: " & thePhrase & " takes you to " & item 3 of line lineNum of field "BOLD List"
  137.   
  138.   if off > 0 then 
  139.     goGo(item 3 of line lineNum of field "BOLD List")  
  140.     exit
  141.   else 
  142.     alert "The BOLD term clicked was: " & quote & thePhrase & quote && "in cast " & cn ¼
  143. & ", but it can not be found in the bold list."
  144.     exit
  145.   end if
  146. end doBoldText
  147.  
  148. on doUnderlineText mc, cn
  149.   global gGlossPalette, gPunctuation
  150.   
  151.   cursor 4
  152.   
  153.   set thePhrase = char mc of field cn
  154.   
  155.   set i = mc - 1 
  156.   
  157.   repeat while i > 0
  158.     if (the textStyle of char i of field cn) <> "underline" then exit repeat
  159.     set thePhrase = char i of field cn & thePhrase
  160.     set i = i - 1
  161.   end repeat
  162.   
  163.   set i = mc + 1 
  164.   set last = the number of chars of field cn
  165.   
  166.   repeat while i <= last
  167.     if (the textStyle of char i of field cn) <> "underline" then exit repeat
  168.     set thePhrase = thePhrase & char i of field cn 
  169.     set i = i + 1
  170.   end repeat
  171.   
  172.   set l = the number of chars in thePhrase
  173.   
  174.   repeat while gPunctuation contains (char l of thePhrase)
  175.     set l = l - 1
  176.   end repeat
  177.   
  178.   set thePhrase = char 1 to l of thePhrase
  179.   
  180.   --put ">>>doTextClick: underline" && thePhrase
  181.   
  182.   set glossCN = underLineLookUp(thePhrase, cn)
  183.   
  184.   if glossCN = 0 then
  185.     alert "Term not found in the glossary. Term clicked was: " ¼
  186. & quote & thePhrase & quote && "in cast " & cn
  187.   else   
  188.     if voidP(gGlossPalette) then 
  189.       createGlossPalette 
  190.     end if
  191.     
  192.     tell gGlossPalette to showTermCast(glossCN)
  193.     tell gGlossPalette to lOpenGlossPalette
  194.   end if
  195.   
  196.   cursor -1
  197.   
  198. end doUnderlineText
  199.  
  200.